package dry.example.gui;

import javax.swing.*;
import java.awt.*;

public class GridLayoutExample {

    public static void main(String[] args) {
        JFrame.setDefaultLookAndFeelDecorated(false);
        // 创建 JFrame 实例
        JFrame frame = new JFrame("GridLayout 示例");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 300);

        // 设置 GridLayout：3 行，2 列，组件之间的水平和垂直间距为 5 像素
        GridLayout gridLayout = new GridLayout(3, 2, 5, 5);
        frame.setLayout(gridLayout);

        // 添加一些 JButton 组件
        String[] buttonLabels = {"按钮1", "按钮2", "按钮3", "按钮4", "按钮5", "按钮6"};
        for (String label : buttonLabels) {
            JButton button = new JButton(label);
            frame.add(button);
        }

        // 显示窗口
        frame.pack(); // 自动调整窗口大小以适应内容
        frame.setLocationRelativeTo(null); // 居中显示
        frame.setVisible(true);
    }

}
